package com.mgface.eth.example;

import org.web3j.abi.EventEncoder;
import org.web3j.abi.TypeReference;
import org.web3j.abi.datatypes.Address;
import org.web3j.abi.datatypes.Event;
import org.web3j.abi.datatypes.Function;
import org.web3j.abi.datatypes.Type;
import org.web3j.abi.datatypes.generated.StaticArray3;
import org.web3j.abi.datatypes.generated.Uint256;
import org.web3j.crypto.Credentials;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.DefaultBlockParameter;
import org.web3j.protocol.core.RemoteCall;
import org.web3j.protocol.core.methods.request.EthFilter;
import org.web3j.protocol.core.methods.response.Log;
import org.web3j.protocol.core.methods.response.TransactionReceipt;
import org.web3j.tx.Contract;
import org.web3j.tx.TransactionManager;
import rx.Observable;
import rx.functions.Func1;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * <p>Auto generated code.
 * <p><strong>Do not modify!</strong>
 * <p>Please use the <a href="https://docs.web3j.io/command_line.html">web3j command line tools</a>,
 * or the org.web3j.codegen.SolidityFunctionWrapperGenerator in the 
 * <a href="https://github.com/web3j/web3j/tree/master/codegen">codegen module</a> to update.
 *
 * <p>Generated with web3j version 3.4.0.
 */
public class Compute extends Contract {
    private static final String BINARY = "60606040525b336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505b5b610610806100566000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806303e9e6091461005f57806313af4035146100bf5780638da5cb5b146100f85780639c17139e1461014d575b600080fd5b341561006a57600080fd5b610080600480803590602001909190505061018d565b6040518082600360200280838360005b838110156100ac5780820151818401525b602081019050610090565b5050505090500191505060405180910390f35b34156100ca57600080fd5b6100f6600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610256565b005b341561010357600080fd5b61010b610328565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b341561015857600080fd5b610177600480803590602001909190803590602001909190505061034d565b6040518082815260200191505060405180910390f35b6101956104e4565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156101f057600080fd5b6001828154811015156101ff57fe5b906000526020600020906003020160005b50600380602002604051908101604052809291908260038015610248576020028201915b815481526020019060010190808311610234575b505050505090505b5b919050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156102b157600080fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141515610323578073ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1650505b5b5b50565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000806000806000806000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156103b157600080fd5b868814156103c1578795506104af565b6103cb88886104bb565b8095508196505050600192505b6001156104ad578483029150600084838115156103f157fe5b0614156104a057600180805480600101828161040d919061050c565b916000526020600020906003020160005b6060604051908101604052808d81526020018c815260200187815250909190915090600361044d92919061053e565b500390507ff5589a624e1de338d9c146d63b147fd840c26c11c6f85c0df9a298b13fb5be0b88888460405180848152602001838152602001828152602001935050505060405180910390a18095506104af565b82806001019350506103d8565b5b5b5b505050505092915050565b600080828411156104d1578383915091506104dd565b8284915091506104dd565b5b9250929050565b6060604051908101604052806003905b60008152602001906001900390816104f45790505090565b81548183558181151161053957600302816003028360005260206000209182019101610538919061057e565b5b505050565b826003810192821561056d579160200282015b8281111561056c578251825591602001919060010190610551565b5b50905061057a91906105aa565b5090565b6105a791905b808211156105a3576000818161059a91906105cf565b50600301610584565b5090565b90565b6105cc91905b808211156105c85760008160009055506001016105b0565b5090565b90565b506000815560010160008155600101600090555600a165627a7a72305820f074b53e639b6e9b39b870ea50bb31b0558752775596aef93dc2b2ff43decf4a0029";

    public static final String FUNC_GETRECORD = "getRecord";

    public static final String FUNC_SETOWNER = "setOwner";

    public static final String FUNC_OWNER = "owner";

    public static final String FUNC_GETLCM = "getLCM";

    public static final Event GETLCM_EVENT = new Event("GetLCM", 
            Arrays.<TypeReference<?>>asList(),
            Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}, new TypeReference<Uint256>() {}, new TypeReference<Uint256>() {}));
    ;

    protected Compute(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
        super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit);
    }

    protected Compute(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
        super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit);
    }

    public RemoteCall<StaticArray3<Uint256>> getRecord(Uint256 index) {
        final Function function = new Function(FUNC_GETRECORD, 
                Arrays.<Type>asList(index), 
                Arrays.<TypeReference<?>>asList(new TypeReference<StaticArray3<Uint256>>() {}));
        return executeRemoteCallSingleValueReturn(function);
    }

    public RemoteCall<TransactionReceipt> setOwner(Address to) {
        final Function function = new Function(
                FUNC_SETOWNER, 
                Arrays.<Type>asList(to), 
                Collections.<TypeReference<?>>emptyList());
        return executeRemoteCallTransaction(function);
    }

    public RemoteCall<Address> owner() {
        final Function function = new Function(FUNC_OWNER, 
                Arrays.<Type>asList(), 
                Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}));
        return executeRemoteCallSingleValueReturn(function);
    }

    public RemoteCall<TransactionReceipt> getLCM(Uint256 first, Uint256 second) {
        final Function function = new Function(
                FUNC_GETLCM, 
                Arrays.<Type>asList(first, second), 
                Collections.<TypeReference<?>>emptyList());
        return executeRemoteCallTransaction(function);
    }

    public List<GetLCMEventResponse> getGetLCMEvents(TransactionReceipt transactionReceipt) {
        List<EventValuesWithLog> valueList = extractEventParametersWithLog(GETLCM_EVENT, transactionReceipt);
        ArrayList<GetLCMEventResponse> responses = new ArrayList<GetLCMEventResponse>(valueList.size());
        for (EventValuesWithLog eventValues : valueList) {
            GetLCMEventResponse typedResponse = new GetLCMEventResponse();
            typedResponse.log = eventValues.getLog();
            typedResponse.first = (Uint256) eventValues.getNonIndexedValues().get(0);
            typedResponse.second = (Uint256) eventValues.getNonIndexedValues().get(1);
            typedResponse.result = (Uint256) eventValues.getNonIndexedValues().get(2);
            responses.add(typedResponse);
        }
        return responses;
    }

    public Observable<GetLCMEventResponse> getLCMEventObservable(EthFilter filter) {
        return web3j.ethLogObservable(filter).map(new Func1<Log, GetLCMEventResponse>() {
            @Override
            public GetLCMEventResponse call(Log log) {
                EventValuesWithLog eventValues = extractEventParametersWithLog(GETLCM_EVENT, log);
                GetLCMEventResponse typedResponse = new GetLCMEventResponse();
                typedResponse.log = log;
                typedResponse.first = (Uint256) eventValues.getNonIndexedValues().get(0);
                typedResponse.second = (Uint256) eventValues.getNonIndexedValues().get(1);
                typedResponse.result = (Uint256) eventValues.getNonIndexedValues().get(2);
                return typedResponse;
            }
        });
    }

    public Observable<GetLCMEventResponse> getLCMEventObservable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
        EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
        filter.addSingleTopic(EventEncoder.encode(GETLCM_EVENT));
        return getLCMEventObservable(filter);
    }

    public static RemoteCall<Compute> deploy(Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
        return deployRemoteCall(Compute.class, web3j, credentials, gasPrice, gasLimit, BINARY, "");
    }

    public static RemoteCall<Compute> deploy(Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
        return deployRemoteCall(Compute.class, web3j, transactionManager, gasPrice, gasLimit, BINARY, "");
    }

    public static Compute load(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
        return new Compute(contractAddress, web3j, credentials, gasPrice, gasLimit);
    }

    public static Compute load(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
        return new Compute(contractAddress, web3j, transactionManager, gasPrice, gasLimit);
    }

    public static class GetLCMEventResponse {
        public Log log;

        public Uint256 first;

        public Uint256 second;

        public Uint256 result;
    }
}
